package com.xsy.req;

import com.alibaba.fastjson.JSONObject;
import com.xsy.req.utils.CrmApiUtils;
import com.xsy.req.utils.ResultVo;

import java.util.ArrayList;
import java.util.List;

public class CrmUploadFile {


    public static void main(String[] args) throws Exception {
        new CrmUploadFile().upCrmOaFile();
    }

    public void upCrmOaFile() {
        List<JSONObject> fileList = new ArrayList<>();
        JSONObject file1 = new JSONObject();
        file1.put("fileUrl", "https://xsybucket.s3.cn-north-1.amazonaws.com.cn/3179016257966427/2024/09/19/84ea04eb-8dfa-4b6e-8525-1b2f81ff7939.txt");
        file1.put("fileName", "测试文件.txt");
        fileList.add(file1);

        //JSONObject file2 = new JSONObject();
        //file2.put("fileUrl", "https://xsybucket.s3.cn-north-1.amazonaws.com.cn/3179016257966427/2024/09/06/d16293f3-62b9-4868-b5e1-85026ae7da92.doc");
        //file2.put("fileName", "测试文件.doc");
        //fileList.add(file2);

        ResultVo resultVo = CrmApiUtils.uploadFiles(fileList);
        if (resultVo.getCode() != 200) {
            return;
        }

        /**
         * 请求地址：https://api-p05.xiaoshouyi.com/rest/data/v2.0/scripts/api/xsy/oa/rewriteApprovalInfo
         * 把返回的附件 fileIds (3472820093229708,3472820093344398) 传回之前的日志回写接口（入参 fileIds 不为空代表更新附件,传了 fileIds，可以不用传 approvalLog）
         */
        String fileIds = resultVo.getData().toString();
        System.out.println("fileIds = " + fileIds);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("moduleType", 1);
        jsonObject.put("moduleId", 1);
        jsonObject.put("approvalStatus", 1);
        jsonObject.put("fileIds", fileIds); // 附件id,如果有多个则以逗号分割  3472820093229708,3472820093344398
    }


}
